<%@ page import="zqdb.O_INFO" %>
<%@ page import="zqdb.T_TWO" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>公司维护</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 基本信息管理<span
        class="c-gray en">&gt;</span> 公司维护 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
                                              href="javascript: is_search=''; ii_page = 1; $('#inputSearch').val('');  f_getinfo(); " title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<div class="page-container">
    <div class="text-c"> 查询内容：
        <input type="text" class="input-text" style="width:250px" placeholder="输入公司名称" id="inputSearch" name="">
        <button type="submit" onclick="f_search1()" class="btn btn-success" id="search" name=""><i class="Hui-iconfont">&#xe665;</i>搜索</button>
    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20">
            <span class="l">
                <a href="javascript:" onclick="admin_add('新增公司','800','520')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 新增公司</a>
            </span>
        <span class="r">
            <a href="javascript:" onclick="f_next()" class="btn .btn-secondary radius">下一页</a>
        </span>
        <span class="r">
            <a href="javascript:" onclick="f_prev()" class="btn .btn-secondary radius">上一页</a>
        </span>
        <span class="r" style="padding-top: 6px;">共有数据：[<strong id="count">${list2[0].value01}</strong> 条]</span>
    </div>
    <table style="table-layout:fixed; width: 100%; word-break:break-all;" class="table table-border table-bordered table-bg table-hover table-sort table-responsive" id="tablelist">
        <span class="l" style="padding-top: 6px;">公司列表</span>
        <thead>
        <tr class="text-c" style="height:0px;">
            <th style="width: 40px">流水号</th>
            <th style="width: 60px">公司编号</th>
            <th style="width: 80px">负责人</th>
            <th style="width: 250px">公司名称</th>
            <th style="width: 80px">操作员</th>
            <th style="width: 80px">联系电话</th>
            <th>公司地址</th>
            <th style="width: 40px">状态</th>
            <th style="width: 60px">操作</th>
        </tr>

        </thead>
        <tbody id="datalist">
        </tbody>
    </table>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">

    var ii_page = 1;   //--上一页下一页的计数器
    var ii_row = 20;   //--每页显示的记录数
    var ii_count = 0;
    var is_search="";  //--查询内容，如果查询内容为空，则说明是自然翻页，如果该变量有值，那么翻页则翻查询的结果集，将该值传入存储过程，依靠存储过程判断是自然翻页还是查询翻页

    $(document).ajaxComplete(function(event, xhr, settings) {
        //从http头信息取出 在filter定义的sessionstatus，判断是否是 timeout
        if(xhr.getResponseHeader("sessionstatus")==="timeout"){
            //从http头信息取出登录的url ＝ loginPath
            if(xhr.getResponseHeader("loginPath")){
                window.location.replace(xhr.getResponseHeader("loginPath"));
            }
        }
    });

    $(document).ready(function(){
        f_getinfo();
    });

    function f_prev() {
        if (ii_page > 1)
        {
            ii_page --;
            f_getinfo();
        }
        else
        {
            layer.msg("已是第一页", {icon: 0, time: 1000, area: ['200px', '65px']});
        }
    }

    function f_next() {
        if (ii_page*ii_row < ii_count)
        {
            ii_page ++;
            f_getinfo();
        }
        else
        {
            layer.msg("已是最后一页", {icon: 0, time: 1000, area: ['200px', '65px']});
        }
    }

    function f_getinfo() {
        $.ajax({
            type: 'post',
            url:'com',
            data:{
                URL:'',
                CMD:'ZB',
                VALUE01:(ii_page-1)*ii_row,
                VALUE02:(ii_page)*ii_row,
                VALUE03:is_search
            },
            async: false,
            success: function (data) {
                var jsonobj = JSON.parse(data);

                ii_count = jsonobj.db2[0].VALUE01;
                $("#count").text(ii_count);

                var c_table = $("#datalist");
                c_table.html("");
                var str = "";
                var json1 = jsonobj.db1;
                for(var key in json1){
                    var tip=json1[key].VALUE08.toString();
                    if (tip === '启用') {
                        str += "<tr class='text-c'>" +
                            "<td>" + json1[key].VALUE01.toString() + "</td>" +
                            "<td>" + json1[key].VALUE02.toString() + "</td>" +
                            "<td>" + json1[key].VALUE03.toString() + "</td>" +
                            "<td>" + json1[key].VALUE04.toString() + "</td>" +
                            "<td>" + json1[key].VALUE05.toString() + "</td>" +
                            "<td>" + json1[key].VALUE06.toString() + "</td>" +
                            "<td>" + json1[key].VALUE07.toString() + "</td>" +
                            "<td class='td-status'><span class='label label-success radius'>" + tip + "</span></td>" +
                            "<td class='td-manage'>" +
                            "    <a title=\"禁用\"     onClick=\"admin_stop(this,'10001')\"                  class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe631;</i></a>" +
                            "    <a title=\"编辑\"     onclick=\"admin_edit('操作员修改',this,'800','500')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6df;</i></a>" +
                            "    <a title=\"删除\"     onclick=\"admin_set(this)\"                           class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe63f;</i></a>" +
                            "</td>" +
                            "</tr>";
                    }
                    else if (tip === '禁用')
                    {
                        str += "<tr class='text-c'>" +
                            "<td>" + json1[key].VALUE01.toString() + "</td>" +
                            "<td>" + json1[key].VALUE02.toString() + "</td>" +
                            "<td>" + json1[key].VALUE03.toString() + "</td>" +
                            "<td>" + json1[key].VALUE04.toString() + "</td>" +
                            "<td>" + json1[key].VALUE05.toString() + "</td>" +
                            "<td>" + json1[key].VALUE06.toString() + "</td>" +
                            "<td>" + json1[key].VALUE07.toString() + "</td>" +
                            "<td class='td-status'><span class='label radius'>" + tip + "</span></td>" +
                            "<td class='td-manage'>" +
                            "    <a title=\"启用\"     onClick=\"admin_start(this,'10001')\"                 class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe615;</i></a>" +
                            "    <a title=\"编辑\"     onclick=\"admin_edit('操作员修改',this,'800','500')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6df;</i></a>" +
                            "    <a title=\"删除\"     onclick=\"admin_set(this)\"                           class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe63f;</i></a>" +
                            "</td>" +
                            "</tr>";
                    }
                }
                c_table.html(str);
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                layer.msg('网络异常错误', {icon: 1, time: 1000});
            }
        })
    }

    /*增加*/
    function admin_add(title, w, h) {
        if (title == null || title === '') {  title = false;   }
        if (w == null || w === '') {    w = 800;     }
        if (h == null || h === '') {    h = ($(window).height() - 50);     }

        layer.open({
            type: 2,
            area: [w + 'px', h + 'px'],
            fix: false, //不固定
            maxmin: false,
            shade: 0.4,
            title: title,
            content: 'com?URL=w_dwgl_edit.jsp&CMD=ZD'
        });
    }

    /*禁用*/
    function admin_stop(obj) {
        //--利用JQuery获得当前行的主键值
        var x = $(obj).parent().parent().find("td");
        var y = x.eq(1).text();

        if (y === "1")
        {
            layer.msg('管理总部不可以禁用', {icon: 0, time: 2000});
            return;
        }

        layer.confirm('确认要禁用吗？', function (index) {
            $.ajax({
                type: 'post',
                url: 'com',
                async: false,
                data: {URL:'',
                    CMD: 'ZF',
                    VALUE01: y,
                    VALUE02: '禁用'
                },
                success: function (data) {
                    var jsonobj = JSON.parse(data);
                    var json1 = jsonobj.db1;
                    if (json1[0].VALUE01.toString() === 'ZZ00') {
                        //此处请求后台程序，下方是成功后的前台处理……
                        $(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_start(this)" title="启用" style="text-decoration:none"><i class="Hui-iconfont">&#xe615;</i></a>');
                        $(obj).parents("tr").find(".td-status").html('<span class="label radius">禁用</span>');
                        $(obj).remove();
                        layer.msg('已禁用!', {icon: 5, time: 1000});
                    } else {
                        layer.msg(json1[0].VALUE02.toString(), {icon: 2, time: 2000}, function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    }
                },
                error: function (XmlHttpRequest, textStatus, errorThrown) {
                    layer.msg('网络异常错误', {icon: 1, time: 1000});
                }
            });
        });
    }

    /*启用*/
    function admin_start(obj) {
        var x = $(obj).parent().parent().find("td");
        var y = x.eq(1).text();

        if (y === "1")
        {
            layer.msg('管理总部无需操作', {icon: 0, time: 2000});
            return;
        }

        layer.confirm('确认要启用吗？', function (index) {
            $.ajax({
                type: 'post',
                url: 'com',
                async: false,
                data: {URL:'',
                    CMD: 'ZF',
                    VALUE01: y,
                    VALUE02: '启用'
                },
                success: function (data) {
                    var jsonobj = JSON.parse(data);
                    var json1 = jsonobj.db1;
                    if (json1[0].VALUE01.toString() === 'ZZ00') {
                        //此处请求后台程序，下方是成功后的前台处理……
                        $(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_stop(this)" title="禁用" style="text-decoration:none"><i class="Hui-iconfont">&#xe631;</i></a>');
                        $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">启用</span>');
                        $(obj).remove();
                        layer.msg('已启用!', {icon: 6, time: 1000});
                    } else {
                        layer.msg(json1[0].VALUE02.toString(), {icon: 2, time: 2000, area: ['auto', '65px']}, function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    }
                },
                error: function (XmlHttpRequest, textStatus, errorThrown) {
                    layer.msg('网络异常错误', {icon: 1, time: 1000});
                }
            })
        });
    }

    /*编辑*/
    function admin_edit(title, obj, w, h) {
        if (title == null || title === '') {     title = false;      }
        if (w == null || w === '') {     w = 800;      }
        if (h == null || h === '') {     h = ($(window).height() - 50);        }

        var ls_val = $(obj).parent().parent().find('td').eq(1).text();
        if (ls_val === "1")
        {
            layer.msg('管理总部无需修改', {icon: 0, time: 2000});
            return;
        }

        layer.open({
            type: 2,
            area: [w + 'px', h + 'px'],
            fix: false, //不固定
            maxmin: false,
            shade: 0.4,
            title: title,
            content: 'com?URL=w_dwgl_edit.jsp&CMD=ZG&VALUE01=' + $(obj).parent().parent().find('td').eq(1).text()
        });
    }

    function f_search1() {
        is_search = $("#inputSearch").val()||'';
        if (is_search.length === 0)
        {
            layer.msg('请输入查询内容!', {icon: 1, time: 2000}, function () {
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            });
            return;
        }
        ii_page = 1;   //--上一页下一页的计数器
        is_judd = '1';
        f_getinfo();
    }

    function f_search11() {
        const msg = "${sessionOpid}";
        alert(msg);
    }

</script>
</body>
</html>
